package entities;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;

public class AcdcProgram {
	private String code;
	private ArrayList<String> course = new ArrayList<String>();
	private static HashMap<String, AcdcProgram> programHm = new HashMap<String, AcdcProgram>();

	public AcdcProgram(String code) {
		this.code = code;
		if (programHm.get(code) == null)
			programHm.put(code, this);
	}

	public String getCode() {
		return this.code;
	}

	public void addCourse(String courseCode) {
		this.course.add(courseCode);
	}

	public String[] getCourse() {
		String[] courses = new String[this.course.size()];

		for (int i = 0; i < this.course.size(); i++) {
			courses[i] = this.course.get(i);
		}
		return courses;
	}

	public static AcdcProgram getProgramByCode(String code) {
		return programHm.get(code);
	}

	public static String[] getAllPrograms() {
		Iterator<String> programCode = programHm.keySet().iterator();
		String[] programCodeList = new String[programHm.size()];
		int i = 0;
		while (programCode.hasNext()) {
			programCodeList[i++] = programCode.next();
		}
		Arrays.sort(programCodeList);

		return programCodeList;
	}

	public static void clear() {
		programHm.clear();
	}
}
